//bange_animation.hpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _bange_animation_
#define _bange_animation_

#include <vector>
#include <cstring>
#include <iostream>

#include <SFML/Graphics.hpp>
#include <lua5.1/lua.hpp>

#include <bange_image.hpp>

using namespace std;

namespace bange{
	
	class animation: public sf::Sprite{
		public:
			static void RegisterVM(lua_State *);
			
		struct ananimation{
			float step;
			float storetime;
			bool automatic;
			std::vector<sf::IntRect> frames;
			int iframe;
			sf::IntRect GetSubrect();
		};
		
		static void BuildFramesForAnAnimation(bange::animation::ananimation &, lua_State *);
		
		private:
			int refimage;
			std::vector<bange::animation::ananimation> animations;
			int ianimation;
		public:
			animation();
			~animation();
			bool NewIndex(lua_State *);
			bool Index(lua_State *);
			void Process(float);
			void AddTime(float);
			void CleanVM(lua_State *vm);
		private:
			void SetSubrect();
		
	};
	
}

static int bangeanimation_AddTime(lua_State *);

#endif
